/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.ruby_string.delayed;

import picounit.util.Equal;
import picounit.verify.constraint.EqualUtil;
import moved.org.objectweb.asm.Label;
import moved.org.objectweb.asm.MethodVisitor;

public class TryCatchBlockInstruction extends AbstractMethodInstruction implements Equal<TryCatchBlockInstruction> {
	private final Label start;
	private final Label end;
	private final Label handle;
	private final String type;

	public TryCatchBlockInstruction(Label start, Label end, Label handle, String type) {
		this.start = start;
		this.end = end;
		this.handle = handle;
		this.type = type;
	}
	
	public boolean matches(Label start, Label end, Label handle, String type) {
		return this.start.equals(start) &&
			this.end.equals(end) &&
			this.handle.equals(handle) &&
			this.type.equals(type);
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// Equal methods
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	public boolean equalTo(TryCatchBlockInstruction other) {
		return other.matches(start, end, handle, type);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// MethodInstruction Methods
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	public void accept(MethodVisitor methodVisitor) {
		methodVisitor.visitTryCatchBlock(start, end, handle, type);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Object Methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	@Override
	public boolean equals(Object object) {
		return EqualUtil.isEqual(this, object);
	}
}
